package com.nw.serviceImpl;

import com.nw.dao.ReturnCargoDao;
import com.nw.entity.ReturnCargo;
import com.nw.service.ReturnCargoService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;

@Service
@Transactional

public class ReturnCargoServiceImpl implements ReturnCargoService {
    @Resource
    ReturnCargoDao returnCargoDao;
    @Override
    public HashMap<String, Object> addReturnCargo(ReturnCargo returnCargo) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            returnCargo.setReturnId(UUID.randomUUID().toString());
            returnCargoDao.addReturnCargo(returnCargo);
            map.put("code","0");
            map.put("msg","添加退货成功");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code","1");
            map.put("msg","添加退货失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> deleteReturnCargo(ReturnCargo returnCargo) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            returnCargoDao.deleteReturnCargo(returnCargo);
            map.put("code","0");
            map.put("msg","删除退货成功");
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code","1");
            map.put("msg","删除退货失败");
        }
        return map;
    }

    @Override
    public HashMap<String, Object> queryReturnCargoByUser(String returnUser) {
        HashMap<String, Object> map = new HashMap<>();
        try {
            List<ReturnCargo> returnCargos = returnCargoDao.queryReturnCargoByUser(returnUser);
            map.put("code","0");
            map.put("msg","查询退货成功");
            map.put("data",returnCargos);
        } catch (Exception e) {
            e.printStackTrace();
            map.put("code","1");
            map.put("msg","查询退货失败");
        }
        return map;
    }
}
